package com.demodis.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demodis.dao.GroupDaoI;
import com.demodis.dao.UserDaoI;
import com.demodis.dao.impl.GroupDaoImpl;
import com.demodis.dao.impl.UserDaoImpl;
import com.demodis.domain.TblGroup;
import com.demodis.service.GroupServiceI;

public class GroupServiceImpl implements GroupServiceI {
	
	GroupDaoI groupDao = new GroupDaoImpl();
	UserDaoI userDao = new UserDaoImpl();

	@Override
	public Object getGroup(String flag) {
		List<TblGroup> list= groupDao.getGroup(flag);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", list.size());
		map.put("rows", list);
		return map;
	}

	@Override
	public boolean save(TblGroup group) {
		return groupDao.save(group);
	}

	@Override
	public boolean modify(TblGroup group) {
		return groupDao.modify(group);
	}

	@Override
	public boolean delete(TblGroup group) {
		if(userDao.deleteByGroupId(group.getIds()) && groupDao.delete(group)) {
			return true;
		}
		return false;
	}

	@Override
	public Object getGroupComboBoxData() {
		return groupDao.getGroup("");
	}

	@Override
	public double getChargeGroupResult(int userId) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean saveScore(TblGroup group) {
		return groupDao.saveScore(group.getGroupId(), group.getScore());
	}

}
